package LeetCode;

public class LC_606_ConstructStringfromBinaryTree {

    public static void main(String[] args) {

    }

    public class Solution {
        String tree2str(TreeNode t) {
            if (t == null) return "";
            StringBuilder sb = new StringBuilder();
            sb.append(t.val);
            if (t.right != null)
                sb.append("(").append(tree2str(t.left)).append(")").append("(").append(tree2str(t.right)).append(")");
            else if (t.left != null)
                sb.append("(").append(tree2str(t.left)).append(")");
            return sb.toString();
        }
    }

}